import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _regeneratorRuntime from "@babel/runtime/regenerator";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
var _excluded = ["executorRouteList", "glueTypeList", "executorBlockList", "executorFailList", "sourceFlagList"];

/**
 * model 调度任务
 * @date: 2018-9-3


 */
import { getResponse, createPagination, parseParameters } from 'utils/utils';
import { queryMapIdpValue } from 'cpaas-front/lib/services/api';
import { fetchGroupsList as _fetchGroupsList, fetchJobInfo as _fetchJobInfo, createJobInfo as _createJobInfo, updateJobInfo as _updateJobInfo, deleteJobInfo as _deleteJobInfo, pauseJobInfo as _pauseJobInfo, resumeJobInfo as _resumeJobInfo, triggerJobInfo as _triggerJobInfo, queryJobInfo as _queryJobInfo, updateJobGlue as _updateJobGlue, queryJobGlueList as _queryJobGlueList, queryJobGlueDetail as _queryJobGlueDetail, stopJob as _stopJob, fetchJobLog as _fetchJobLog, fetchJobLogError as _fetchJobLogError, deleteJobLog as _deleteJobLog, fetchProgress as _fetchProgress, copyJobInfo as _copyJobInfo } from "../services/jobInfoService";
import { checkExecutor, executorConfig as _executorConfig, executorConfigByJob as _executorConfigByJob } from "../services/jobGroupService";
export default {
  namespace: 'jobInfo',
  state: {
    jobInfoList: [],
    // 列表数据
    jobInfoDetail: {},
    // 详情数据
    modalVisible: false,
    // 控制模态框显示
    glueList: [],
    // glue更改日志列表
    pagination: {},
    // 分页信息对象
    groupsList: [],
    // 执行器
    executorRouteList: [],
    // 路由策略
    glueTypeList: [],
    // 任务类型
    jobStatusList: [],
    // 状态
    executorBlockList: [],
    // 阻塞处理策略
    executorFailList: [],
    // 失败处理策略
    jobLogList: [],
    // 调度日志列表
    jobPagination: {},
    // 调度日志分页
    jobErrorDetail: {},
    // 调度日志错误详情
    jobLogLdp: {},
    // 调度日志值集
    executorConfigList: [],
    // 执行器配置列表
    sourceFlagList: []
  },
  effects: {
    // 获取初始化数据
    init: /*#__PURE__*/_regeneratorRuntime.mark(function init(_, _ref) {
      var call, put, res, executorRouteList, glueTypeList, executorBlockList, executorFailList, sourceFlagList, jobLogLdp, _jobLogLdp$jobStatusL, jobStatusList;

      return _regeneratorRuntime.wrap(function init$(_context) {
        while (1) {
          switch (_context.prev = _context.next) {
            case 0:
              call = _ref.call, put = _ref.put;
              _context.t0 = getResponse;
              _context.next = 4;
              return call(queryMapIdpValue, {
                jobResultList: 'CSDR.LOG.JOB_RESULT',
                clientResultList: 'CSDR.LOG.CLIENT_RESULT',
                jobStatusList: 'CSDR.JOB_STATUS',
                executorRouteList: 'CSDR.EXECUTOR_STRATEGY',
                glueTypeList: 'CSDR.GLUE_TYPE',
                executorBlockList: 'CSDR.EXECUTOR_BLOCK_STRATEGY',
                executorFailList: 'CSDR.FAIL_STRATEGY',
                sourceFlagList: 'CSDR.JOB.SOURCE_FLAG'
              });

            case 4:
              _context.t1 = _context.sent;
              res = (0, _context.t0)(_context.t1);
              executorRouteList = res.executorRouteList, glueTypeList = res.glueTypeList, executorBlockList = res.executorBlockList, executorFailList = res.executorFailList, sourceFlagList = res.sourceFlagList, jobLogLdp = _objectWithoutProperties(res, _excluded);
              _jobLogLdp$jobStatusL = jobLogLdp.jobStatusList, jobStatusList = _jobLogLdp$jobStatusL === void 0 ? [] : _jobLogLdp$jobStatusL;

              if (!res) {
                _context.next = 11;
                break;
              }

              _context.next = 11;
              return put({
                type: 'updateState',
                payload: {
                  jobLogLdp: jobLogLdp,
                  executorRouteList: executorRouteList,
                  glueTypeList: glueTypeList,
                  jobStatusList: jobStatusList,
                  executorBlockList: executorBlockList,
                  executorFailList: executorFailList,
                  sourceFlagList: sourceFlagList
                }
              });

            case 11:
            case "end":
              return _context.stop();
          }
        }
      }, init);
    }),
    // 获取执行器
    fetchGroupsList: /*#__PURE__*/_regeneratorRuntime.mark(function fetchGroupsList(_, _ref2) {
      var call, put, result;
      return _regeneratorRuntime.wrap(function fetchGroupsList$(_context2) {
        while (1) {
          switch (_context2.prev = _context2.next) {
            case 0:
              call = _ref2.call, put = _ref2.put;
              _context2.t0 = getResponse;
              _context2.next = 4;
              return call(_fetchGroupsList);

            case 4:
              _context2.t1 = _context2.sent;
              result = (0, _context2.t0)(_context2.t1);

              if (!result) {
                _context2.next = 9;
                break;
              }

              _context2.next = 9;
              return put({
                type: 'updateState',
                payload: {
                  groupsList: result
                }
              });

            case 9:
            case "end":
              return _context2.stop();
          }
        }
      }, fetchGroupsList);
    }),
    fetchJobInfo: /*#__PURE__*/_regeneratorRuntime.mark(function fetchJobInfo(_ref3, _ref4) {
      var payload, call, put, res, list;
      return _regeneratorRuntime.wrap(function fetchJobInfo$(_context3) {
        while (1) {
          switch (_context3.prev = _context3.next) {
            case 0:
              payload = _ref3.payload;
              call = _ref4.call, put = _ref4.put;
              _context3.next = 4;
              return call(_fetchJobInfo, parseParameters(payload));

            case 4:
              res = _context3.sent;
              list = getResponse(res);

              if (!list) {
                _context3.next = 9;
                break;
              }

              _context3.next = 9;
              return put({
                type: 'updateState',
                payload: {
                  jobInfoList: list.content,
                  pagination: createPagination(list)
                }
              });

            case 9:
            case "end":
              return _context3.stop();
          }
        }
      }, fetchJobInfo);
    }),
    // 查询job详情
    queryJobInfo: /*#__PURE__*/_regeneratorRuntime.mark(function queryJobInfo(_ref5, _ref6) {
      var payload, call, put, res, list;
      return _regeneratorRuntime.wrap(function queryJobInfo$(_context4) {
        while (1) {
          switch (_context4.prev = _context4.next) {
            case 0:
              payload = _ref5.payload;
              call = _ref6.call, put = _ref6.put;
              _context4.next = 4;
              return call(_queryJobInfo, payload);

            case 4:
              res = _context4.sent;
              list = getResponse(res);

              if (!list) {
                _context4.next = 9;
                break;
              }

              _context4.next = 9;
              return put({
                type: 'updateState',
                payload: {
                  jobInfoDetail: list
                }
              });

            case 9:
              return _context4.abrupt("return", list);

            case 10:
            case "end":
              return _context4.stop();
          }
        }
      }, queryJobInfo);
    }),
    // 查询glue详情
    queryJobGlueDetail: /*#__PURE__*/_regeneratorRuntime.mark(function queryJobGlueDetail(_ref7, _ref8) {
      var payload, call, put, res, list;
      return _regeneratorRuntime.wrap(function queryJobGlueDetail$(_context5) {
        while (1) {
          switch (_context5.prev = _context5.next) {
            case 0:
              payload = _ref7.payload;
              call = _ref8.call, put = _ref8.put;
              _context5.next = 4;
              return call(_queryJobGlueDetail, payload);

            case 4:
              res = _context5.sent;
              list = getResponse(res);

              if (!list) {
                _context5.next = 9;
                break;
              }

              _context5.next = 9;
              return put({
                type: 'updateState',
                payload: {
                  jobInfoDetail: list
                }
              });

            case 9:
              return _context5.abrupt("return", list);

            case 10:
            case "end":
              return _context5.stop();
          }
        }
      }, queryJobGlueDetail);
    }),
    queryJobGlueList: /*#__PURE__*/_regeneratorRuntime.mark(function queryJobGlueList(_ref9, _ref10) {
      var payload, call, put, res, list;
      return _regeneratorRuntime.wrap(function queryJobGlueList$(_context6) {
        while (1) {
          switch (_context6.prev = _context6.next) {
            case 0:
              payload = _ref9.payload;
              call = _ref10.call, put = _ref10.put;
              _context6.next = 4;
              return call(_queryJobGlueList, payload);

            case 4:
              res = _context6.sent;
              list = getResponse(res);

              if (!list) {
                _context6.next = 9;
                break;
              }

              _context6.next = 9;
              return put({
                type: 'updateState',
                payload: {
                  glueList: list
                }
              });

            case 9:
              return _context6.abrupt("return", list);

            case 10:
            case "end":
              return _context6.stop();
          }
        }
      }, queryJobGlueList);
    }),
    // 查询调度日志
    fetchJobLog: /*#__PURE__*/_regeneratorRuntime.mark(function fetchJobLog(_ref11, _ref12) {
      var payload, call, put, res, result;
      return _regeneratorRuntime.wrap(function fetchJobLog$(_context7) {
        while (1) {
          switch (_context7.prev = _context7.next) {
            case 0:
              payload = _ref11.payload;
              call = _ref12.call, put = _ref12.put;
              _context7.next = 4;
              return call(_fetchJobLog, payload);

            case 4:
              res = _context7.sent;
              result = getResponse(res);

              if (!result) {
                _context7.next = 9;
                break;
              }

              _context7.next = 9;
              return put({
                type: 'updateState',
                payload: {
                  jobLogList: result.content,
                  jobPagination: createPagination(result)
                }
              });

            case 9:
              return _context7.abrupt("return", result);

            case 10:
            case "end":
              return _context7.stop();
          }
        }
      }, fetchJobLog);
    }),
    // 查询调度日志错误详情
    fetchJobLogError: /*#__PURE__*/_regeneratorRuntime.mark(function fetchJobLogError(_ref13, _ref14) {
      var payload, call, put, res, result;
      return _regeneratorRuntime.wrap(function fetchJobLogError$(_context8) {
        while (1) {
          switch (_context8.prev = _context8.next) {
            case 0:
              payload = _ref13.payload;
              call = _ref14.call, put = _ref14.put;
              _context8.next = 4;
              return call(_fetchJobLogError, payload);

            case 4:
              res = _context8.sent;
              result = getResponse(res);

              if (!result) {
                _context8.next = 9;
                break;
              }

              _context8.next = 9;
              return put({
                type: 'updateState',
                payload: {
                  jobErrorDetail: result
                }
              });

            case 9:
              return _context8.abrupt("return", result);

            case 10:
            case "end":
              return _context8.stop();
          }
        }
      }, fetchJobLogError);
    }),
    // 删除调度日志
    deleteJobLog: /*#__PURE__*/_regeneratorRuntime.mark(function deleteJobLog(_ref15, _ref16) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function deleteJobLog$(_context9) {
        while (1) {
          switch (_context9.prev = _context9.next) {
            case 0:
              payload = _ref15.payload;
              call = _ref16.call;
              _context9.next = 4;
              return call(_deleteJobLog, payload);

            case 4:
              res = _context9.sent;
              return _context9.abrupt("return", getResponse(res));

            case 6:
            case "end":
              return _context9.stop();
          }
        }
      }, deleteJobLog);
    }),
    // 创建
    createJobInfo: /*#__PURE__*/_regeneratorRuntime.mark(function createJobInfo(_ref17, _ref18) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function createJobInfo$(_context10) {
        while (1) {
          switch (_context10.prev = _context10.next) {
            case 0:
              payload = _ref17.payload;
              call = _ref18.call;
              _context10.next = 4;
              return call(_createJobInfo, payload);

            case 4:
              res = _context10.sent;
              return _context10.abrupt("return", getResponse(res));

            case 6:
            case "end":
              return _context10.stop();
          }
        }
      }, createJobInfo);
    }),
    // 更新
    updateJobInfo: /*#__PURE__*/_regeneratorRuntime.mark(function updateJobInfo(_ref19, _ref20) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function updateJobInfo$(_context11) {
        while (1) {
          switch (_context11.prev = _context11.next) {
            case 0:
              payload = _ref19.payload;
              call = _ref20.call;
              _context11.next = 4;
              return call(_updateJobInfo, payload);

            case 4:
              res = _context11.sent;
              return _context11.abrupt("return", getResponse(res));

            case 6:
            case "end":
              return _context11.stop();
          }
        }
      }, updateJobInfo);
    }),
    // 更新glue
    updateJobGlue: /*#__PURE__*/_regeneratorRuntime.mark(function updateJobGlue(_ref21, _ref22) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function updateJobGlue$(_context12) {
        while (1) {
          switch (_context12.prev = _context12.next) {
            case 0:
              payload = _ref21.payload;
              call = _ref22.call;
              _context12.next = 4;
              return call(_updateJobGlue, payload);

            case 4:
              res = _context12.sent;
              return _context12.abrupt("return", getResponse(res));

            case 6:
            case "end":
              return _context12.stop();
          }
        }
      }, updateJobGlue);
    }),
    // 删除
    deleteJobInfo: /*#__PURE__*/_regeneratorRuntime.mark(function deleteJobInfo(_ref23, _ref24) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function deleteJobInfo$(_context13) {
        while (1) {
          switch (_context13.prev = _context13.next) {
            case 0:
              payload = _ref23.payload;
              call = _ref24.call;
              _context13.next = 4;
              return call(_deleteJobInfo, payload);

            case 4:
              res = _context13.sent;
              return _context13.abrupt("return", getResponse(res));

            case 6:
            case "end":
              return _context13.stop();
          }
        }
      }, deleteJobInfo);
    }),
    // 暂停
    pauseJobInfo: /*#__PURE__*/_regeneratorRuntime.mark(function pauseJobInfo(_ref25, _ref26) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function pauseJobInfo$(_context14) {
        while (1) {
          switch (_context14.prev = _context14.next) {
            case 0:
              payload = _ref25.payload;
              call = _ref26.call;
              _context14.next = 4;
              return call(_pauseJobInfo, payload);

            case 4:
              res = _context14.sent;
              return _context14.abrupt("return", getResponse(res));

            case 6:
            case "end":
              return _context14.stop();
          }
        }
      }, pauseJobInfo);
    }),
    // 恢复
    resumeJobInfo: /*#__PURE__*/_regeneratorRuntime.mark(function resumeJobInfo(_ref27, _ref28) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function resumeJobInfo$(_context15) {
        while (1) {
          switch (_context15.prev = _context15.next) {
            case 0:
              payload = _ref27.payload;
              call = _ref28.call;
              _context15.next = 4;
              return call(_resumeJobInfo, payload);

            case 4:
              res = _context15.sent;
              return _context15.abrupt("return", getResponse(res));

            case 6:
            case "end":
              return _context15.stop();
          }
        }
      }, resumeJobInfo);
    }),
    // 执行
    triggerJobInfo: /*#__PURE__*/_regeneratorRuntime.mark(function triggerJobInfo(_ref29, _ref30) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function triggerJobInfo$(_context16) {
        while (1) {
          switch (_context16.prev = _context16.next) {
            case 0:
              payload = _ref29.payload;
              call = _ref30.call;
              _context16.next = 4;
              return call(_triggerJobInfo, payload);

            case 4:
              res = _context16.sent;
              return _context16.abrupt("return", getResponse(res));

            case 6:
            case "end":
              return _context16.stop();
          }
        }
      }, triggerJobInfo);
    }),
    // 终止
    stopJob: /*#__PURE__*/_regeneratorRuntime.mark(function stopJob(_ref31, _ref32) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function stopJob$(_context17) {
        while (1) {
          switch (_context17.prev = _context17.next) {
            case 0:
              payload = _ref31.payload;
              call = _ref32.call;
              _context17.next = 4;
              return call(_stopJob, payload);

            case 4:
              res = _context17.sent;
              return _context17.abrupt("return", getResponse(res));

            case 6:
            case "end":
              return _context17.stop();
          }
        }
      }, stopJob);
    }),
    // 获取任务进度
    fetchProgress: /*#__PURE__*/_regeneratorRuntime.mark(function fetchProgress(_ref33, _ref34) {
      var payload, call, result;
      return _regeneratorRuntime.wrap(function fetchProgress$(_context18) {
        while (1) {
          switch (_context18.prev = _context18.next) {
            case 0:
              payload = _ref33.payload;
              call = _ref34.call;
              _context18.next = 4;
              return call(_fetchProgress, payload);

            case 4:
              result = _context18.sent;
              return _context18.abrupt("return", getResponse(result));

            case 6:
            case "end":
              return _context18.stop();
          }
        }
      }, fetchProgress);
    }),
    // 检查
    checkJobInfo: /*#__PURE__*/_regeneratorRuntime.mark(function checkJobInfo(_ref35, _ref36) {
      var payload, call, result;
      return _regeneratorRuntime.wrap(function checkJobInfo$(_context19) {
        while (1) {
          switch (_context19.prev = _context19.next) {
            case 0:
              payload = _ref35.payload;
              call = _ref36.call;
              _context19.next = 4;
              return call(checkExecutor, payload);

            case 4:
              result = _context19.sent;
              return _context19.abrupt("return", getResponse(result));

            case 6:
            case "end":
              return _context19.stop();
          }
        }
      }, checkJobInfo);
    }),
    // 执行器配置列表
    executorConfig: /*#__PURE__*/_regeneratorRuntime.mark(function executorConfig(_ref37, _ref38) {
      var payload, call, result, res;
      return _regeneratorRuntime.wrap(function executorConfig$(_context20) {
        while (1) {
          switch (_context20.prev = _context20.next) {
            case 0:
              payload = _ref37.payload;
              call = _ref38.call;
              _context20.next = 4;
              return call(_executorConfig, payload);

            case 4:
              result = _context20.sent;
              res = getResponse(result); // if (res) {
              //   yield put({
              //     type: 'updateState',
              //     payload: {
              //       executorConfigList: res,
              //     },
              //   });
              // }

              return _context20.abrupt("return", res);

            case 7:
            case "end":
              return _context20.stop();
          }
        }
      }, executorConfig);
    }),
    // 执行器配置列表
    executorConfigByJob: /*#__PURE__*/_regeneratorRuntime.mark(function executorConfigByJob(_ref39, _ref40) {
      var payload, call, result, res;
      return _regeneratorRuntime.wrap(function executorConfigByJob$(_context21) {
        while (1) {
          switch (_context21.prev = _context21.next) {
            case 0:
              payload = _ref39.payload;
              call = _ref40.call;
              _context21.next = 4;
              return call(_executorConfigByJob, payload);

            case 4:
              result = _context21.sent;
              res = getResponse(result);
              return _context21.abrupt("return", res);

            case 7:
            case "end":
              return _context21.stop();
          }
        }
      }, executorConfigByJob);
    }),
    // 复制
    copyJobInfo: /*#__PURE__*/_regeneratorRuntime.mark(function copyJobInfo(_ref41, _ref42) {
      var payload, call, result;
      return _regeneratorRuntime.wrap(function copyJobInfo$(_context22) {
        while (1) {
          switch (_context22.prev = _context22.next) {
            case 0:
              payload = _ref41.payload;
              call = _ref42.call;
              _context22.next = 4;
              return call(_copyJobInfo, payload);

            case 4:
              result = _context22.sent;
              return _context22.abrupt("return", getResponse(result));

            case 6:
            case "end":
              return _context22.stop();
          }
        }
      }, copyJobInfo);
    })
  },
  reducers: {
    updateState: function updateState(state, _ref43) {
      var payload = _ref43.payload;
      return _objectSpread(_objectSpread({}, state), payload);
    }
  }
};